
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.ListModel;
import javax.swing.SpinnerListModel;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import javax.swing.DefaultComboBoxModel;
   
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewSwingApp extends javax.swing.JFrame {
	private JDesktopPane jDesktopPane1;
	private JButton jButton2;
	private JLabel jLabel4;
	private JButton jButton6;
	private JLabel jLabel5;
	private JTextField jTextField4;
	private JList jList1;
	private JScrollPane jScrollPane1;
	private JButton jButton5;
	private JTextField jTextField3;
	private JButton jButton4;
	private JLabel jLabel3;
	private JButton jButton3;
	private JButton jButton1;
	private JTextField jTextField2;
	private JTextField jTextField1;
	private JLabel jLabel2;
	private JLabel jLabel1;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		NewSwingApp inst = new NewSwingApp();
		inst.setVisible(true);
	}
	
	public NewSwingApp() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setTitle("hello world!");
			{
				jDesktopPane1 = new JDesktopPane();
				getContentPane().add(jDesktopPane1, BorderLayout.CENTER);
				jDesktopPane1.setBounds(0, 0, 500, 400);
				jDesktopPane1.setPreferredSize(new java.awt.Dimension(490, 420));
				{
					jLabel1 = new JLabel();
					jDesktopPane1.add(jLabel1);
					jLabel1.setText("HOST:");
					jLabel1.setBounds(7, 7, 56, 21);
				}
				{
					jLabel2 = new JLabel();
					jDesktopPane1.add(jLabel2);
					jLabel2.setText("PORT:");
					jLabel2.setBounds(175, 7, 42, 21);
				}
				{
					jButton2 = new JButton();
					jDesktopPane1.add(jButton2);
					jButton2.setText("close");
					jButton2.setBounds(399, 7, 77, 21);
					jButton2.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton2ActionPerformed(evt);
						}
					});
				}
				{
					jTextField2 = new JTextField();
					jDesktopPane1.add(jTextField2);
					jTextField2.setBounds(210, 7, 63, 21);
					jTextField2.setText("2010");
				}
				{
					jTextField1 = new JTextField();
					jDesktopPane1.add(jTextField1);
					jTextField1.setBounds(42, 7, 126, 21);
					jTextField1.setText("127.0.0.1");
				}
				{
					jButton1 = new JButton();
					jDesktopPane1.add(jButton1);
					jButton1.setText("Connect");
					jButton1.setBounds(280, 7, 112, 21);
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton1ActionPerformed(evt);
						}
					});
				}
				{
					jButton3 = new JButton();
					jDesktopPane1.add(jButton3);
					jButton3.setText("Watch target screen");
					jButton3.setBounds(77, 91, 196, 21);
					jButton3.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton3ActionPerformed(evt);
						}
					});
				}
				{
					jLabel3 = new JLabel();
					jDesktopPane1.add(jLabel3);
					jLabel3.setText("Function:");
					jLabel3.setBounds(7, 70, 161, 28);
				}
				{
					jLabel4 = new JLabel();
					jDesktopPane1.add(jLabel4);
					jLabel4.setText("connection status...");
					jLabel4.setBounds(7, 35, 175, 21);
				}
				{
					jButton4 = new JButton();
					jDesktopPane1.add(jButton4);
					jButton4.setBounds(0, 56, 490, 7);
				}
				{
					jTextField3 = new JTextField();
					jDesktopPane1.add(jTextField3);
					jTextField3.setBounds(77, 126, 238, 21);
				}
				{
					jButton5 = new JButton();
					jDesktopPane1.add(jButton5);
					jButton5.setText("Submit");
					jButton5.setBounds(322, 126, 77, 21);
					jButton5.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton5ActionPerformed(evt);
						}
					});
				}
				{
					jScrollPane1 = new JScrollPane();
					jDesktopPane1.add(jScrollPane1);
					jScrollPane1.setBounds(98, 161, 224, 182);
					{
						java.util.Vector listData = new java.util.Vector();
						listData.add("all datas");
						jList1 = new JList();
						jScrollPane1.setViewportView(jList1);
						jList1.setListData(listData);
						jList1.setBounds(97, 168, 221, 1560);
						jList1.addMouseListener(new MouseAdapter() {
							public void mouseClicked(MouseEvent evt) {
								jList1MouseClicked(evt);
							}
						});
					}
				}
				{
					jTextField4 = new JTextField();
					jDesktopPane1.add(jTextField4);
					jTextField4.setText("c://hello");
					jTextField4.setBounds(84, 378, 301, 28);
				}
				{
					jLabel5 = new JLabel();
					jDesktopPane1.add(jLabel5);
					jLabel5.setText("copy to:");
					jLabel5.setBounds(35, 378, 77, 28);
				}
				{
					jButton6 = new JButton();
					jDesktopPane1.add(jButton6);
					jButton6.setText("Dialog with target computer");
					jButton6.setBounds(287, 91, 196, 21);
					jButton6.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							jButton6ActionPerformed(evt);
						}
					});
				}
			}
			this.setBounds(300, 200, 500, 500);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void jButton2ActionPerformed(ActionEvent evt) {
		System.exit(1);
	}
	private java.net.Socket socket=null;
	private void jButton3ActionPerformed(ActionEvent evt) {
		if(socket.isClosed()){
			String host = jTextField1.getText().trim();
			int port = Integer.parseInt(jTextField2.getText().trim());
			try{
				this.socket = new Socket(host,port);
				this.jLabel4.setText("connection success!");
			}catch(Exception e){
				this.jLabel4.setText("connection failure!");
			}
		}
		ScreenFrame screenPanal = new ScreenFrame(socket);
		screenPanal.setVisible(true);
	}

	private void jButton1ActionPerformed(ActionEvent evt) {
		
		String host = jTextField1.getText().trim();
		int port = Integer.parseInt(jTextField2.getText().trim());
		try{
			this.socket = new Socket(host,port);
			this.jLabel4.setText("connection success!");
		}catch(Exception e){
			this.jLabel4.setText("connection failure!");
		}
	}
	//operator file
	private void jButton5ActionPerformed(ActionEvent evt) {
		if(socket.isClosed()){
			String host = jTextField1.getText().trim();
			int port = Integer.parseInt(jTextField2.getText().trim());
			try{
				this.socket = new Socket(host,port);
				this.jLabel4.setText("connection success!");
			}catch(Exception e){
				this.jLabel4.setText("connection failure!");
			}
		}
		OperatorFile opfile = new OperatorFile(this.socket,jTextField3.getText(),jTextField4.getText());
		java.util.Vector dlist1 = new java.util.Vector();
		dlist1=opfile.getDataList();
		jList1.setListData(dlist1);
	}
	
	private void jList1MouseClicked(MouseEvent evt) {
		if(socket.isClosed()){
			String host = jTextField1.getText().trim();
			int port = Integer.parseInt(jTextField2.getText().trim());
			try{
				this.socket = new Socket(host,port);
				this.jLabel4.setText("connection success!");
			}catch(Exception e){
				this.jLabel4.setText("connection failure!");
			}
		}
		
		String file = jList1.getSelectedValue().toString();
		OperatorFile opfile = new OperatorFile(this.socket,jTextField3.getText()+"//"+file,jTextField4.getText());
		java.util.Vector dlist1 = opfile.getDataList();
		if(dlist1==null){
			dlist1 = new java.util.Vector();
			dlist1.add("it is a file");
		}
		jList1.setListData(dlist1);	
		jTextField3.setText(jTextField3.getText()+"//"+file);
		

	}
	
	private void jButton6ActionPerformed(ActionEvent evt) {
		String host = jTextField1.getText().trim();
		int port = Integer.parseInt(jTextField2.getText().trim());
		JFrame frame = new JFrame();
		NewJDialog inst = new NewJDialog(frame,socket,host,port);
		inst.setVisible(true);
	}
}


